﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>前锋图书管理系统</title>
    <link rel="stylesheet" href="/css/public.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
</head>
<style>
html,body{
        width: 100%;
        height: 100%;
    }
    .homeWrap{
        width: 100%;height: 100%;
        padding-top: 76px;position: relative;box-sizing: border-box;overflow: hidden;
    }
    .homeWrap div{box-sizing: border-box;}
.publicMian,.left{height: 100%;}
    .homeHeader{width: 100%; position: absolute;left: 0;top: 0;}
    .apply input{
        margin: 10px;
        width: 100px;
        padding: 0 20px;
        height: 30px;
        border: 1px solid #7ba92c;
        border-radius: 4px;
        color: #2f0808;
        font-weight: bold;
    }
    .iscolor{
        background: #6d7982;
    }
    .hiden{
        display: none;
    }
</style>
<body style="line-height: 24px;font: 14px Helvetica Neue,Helvetica,PingFang SC,\5FAE\8F6F\96C5\9ED1,Tahoma,Arial,sans-serif;">
<!--头部-->
<div class="homeWrap">
    <div class="homeHeader">
        <header class="publicHeader">
            <h1>前锋图书管理系统</h1>
            <div class="publicHeaderR">
                <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
                <a href="/admin/index/signOut">退出</a>
            </div>
        </header>

        <!--时间-->
        <section class="publicTime">
            <span id="time">2015年1月1日 11:11  星期一</span>
        </section>
    </div>
<!--主体内容-->
<section class="publicMian">
    <div class="left">
        <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
        <nav>
            <ul class="list">
                <li><a href="/admin/home/home">首页</a></li>
                <li id="active"><a href="/admin/home/borrowingmanagement">借阅管理</a></li>
                <li><a href="/admin/home/bookrecord">图书记录</a></li>
                <li><a href="/admin/home/bookadd">图书添加</a></li>
                <li><a href="/admin/scrollmember/scroll">滚屏</a></li>
                <li><a href="/admin/scrollmember/member">会员管理</a></li>
                <li><a href="/admin/home/editpass">修改密码</a></li>
                <li><a href="/admin/home/groupbuy">团队来源</a></li>
            </ul>
        </nav>
    </div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>借阅管理</span>
        </div>
        <div class="search">
            <span>搜索：</span>
            <input type="text" placeholder="请输入书/用户的名称" id="content"/>
            <input type="button" value="查询" id="search"/>
        </div>
        <div class="apply">
            <input type="button" value="借阅申请" onclick="selectColumn(1)" class="clickOn iscolor"/>
            <input type="button" value="归还申请" onclick="selectColumn(2)" class="clickOn" />
            <input type="button" value="预约申请" onclick="selectColumn(3)" class="clickOn" />
        </div>
        <!--借阅申请-->
        <div class="record">

        </div>
        <!--归还申请-->
        <div class="record hiden">

        </div>
        <!--预约申请-->
        <div class="record hiden">

        </div>
        <div class="pagePage" style="top: 880px;">
            <div class="page_control">
                <div class="pagination"></div>
            </div>
        </div>
    </div>

</section>
</div>

<script src="/js/jquery.js"></script>
<script src="/js/js.js"></script>
<script src="/js/time.js"></script>
<script src="/js/layer/layer.js"></script>
<script src="/js/jquery.paging.js"></script>

<script>
    var index = 1;
    // 初始化状态
    $(document).ready(function () {
        page(index)
    })
    // 选择栏目标题
    function selectColumn(id){
        index = id;
        $(".clickOn").removeClass("iscolor");
        $(".clickOn").eq(id-1).addClass("iscolor");
        $(".record").addClass("hiden");
        $(".record").eq(id-1).removeClass("hiden");
        $(".pagination").empty();
        page(index);
    }
    // 时间戳转换成日期
    function unix_to_datetime(unix) {
        var now = new Date(parseInt(unix) * 1000);
        return now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
    }
    // 分页
    function page(index){
        $('.pagination').paging({
            total: '',
            currentPage: '',
            showPage: 5,        //显示的页数
            animation: false,
            showJump: false,
            ajaxSubmitType: 'post',
            simpleType: 1,
            url: '/admin/home/pageManagement',
            idParameter: "page",
            ajaxData: {'pageType': index},
            beforeAjaxSubmit: function () {
                PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
            },
            ajaxSubmitBack: function (data) {
                console.log(data);
                $('.record').eq(index-1).empty();
                var orderinfo = data.data;
                var type = data.type;
                if(orderinfo=='' ||orderinfo==undefined){
                    $(".record").eq(index-1).html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                    $(".pagination").hide();
                }else{
                    $(".pagination").show();
                    var infohtml="";
                    if(type == 1){
                        infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">';
                        infohtml += '<tr class="firstTr">';
                        infohtml += '<th width="203px !important">图片</th>';
                        infohtml += '<th width="10%">书名</th>';
                        infohtml += '<th width="10%">申请人</th>';
                        infohtml += '<th width="10%">申请时间</th>';
                        infohtml += '<th width="10%">操作</th>';
                        infohtml += '</tr>';
                        $.each(orderinfo,function(index,value){
                            infohtml += '<tr>';
                            infohtml += '<td class="tdclass">'
                            infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                            infohtml += '</td>'
                            infohtml += '<td>'+value['bname']+'</td>'
                            infohtml += '<td>'+value['name']+'</td>'
                            infohtml += '<td>'+unix_to_datetime(value['applybooktime'])+'</td>'
                            infohtml += '<td>'
                            if(value['expect'] == 1){
                                infohtml += '<input type="button" onclick="" value="同意" id="agree" class="anniu" style="visibility: hidden;"/>';
                                infohtml += '<input type="button" onclick="buttonRefuse1('+value['id']+')" value="驳回" class="anniu"/>';
                            }
                            else{
                                infohtml += '<input type="button" onclick="buttonAgree1('+value['id']+','+value['bid']+','+value['uid']+')" value="同意" id="agree" class="anniu"/>';
                                infohtml += '<input type="button" onclick="buttonRefuse1('+value['id']+')" value="驳回" class="anniu"/>';
                            }

                            infohtml += '</td>'
                            infohtml += '</tr>'
                        });
                        infohtml += '</table>';
                    }
                    // 归还申请
                    else if(type == 2){
                        infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">';
                        infohtml += '<tr class="firstTr">';
                        infohtml += '<th width="10%">图片</th>';
                        infohtml += '<th width="10%">书名</th>';
                        infohtml += '<th width="10%">借阅人</th>';
                        infohtml += '<th width="10%">借阅时间</th>';
                        infohtml += '<th width="10%">逾期时间</th>';
                        infohtml += '<th width="10%">操作</th>';
                        infohtml += '</tr>';
                        $.each(orderinfo,function(index,value){
                            infohtml += '<tr>';
                            infohtml += '<td class="tdclass">'
                            infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                            infohtml += '</td>'
                            infohtml += '<td>'+value['bname']+'</td>'
                            infohtml += '<td>'+value['name']+'</td>'
                            if(value['returntime'] == ''){
                                infohtml += '<td>' + unix_to_datetime(value['booktime']) + '-至今</td>'
                            }
                            else {
                                infohtml += '<td>' + unix_to_datetime(value['booktime']) + '-' + unix_to_datetime(value['returntime']) + '</td>'
                            }

                            if(value['isBeOverdue'] == ''){
                                infohtml += '<td>未逾期</td>';
                            }
                            else{
                                infohtml += '<td>'+value['isBeOverdue']+'天</td>';
                            }
                            infohtml += '<td>'
                            infohtml += '<input type="button" onclick="buttonAgree2('+value['id']+','+value['bid']+','+value['uid']+')" value="同意" class="anniu"/>';
                            infohtml += '<input type="button" onclick="buttonRefuse2('+value['id']+')" value="驳回" class="anniu"/>';
                            infohtml += '</td>';
                            infohtml += '</tr>'
                        });
                        infohtml += '</table>';
                    }
                    else if(type == 3){
                        infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">';
                        infohtml += '<tr class="firstTr">';
                        infohtml += '<th width="10%">图片</th>';
                        infohtml += '<th width="10%">书名</th>';
                        infohtml += '<th width="10%">借阅人</th>';
                        infohtml += '<th width="10%">预约时间</th>';
                        infohtml += '</tr>';
                        $.each(orderinfo,function(index,value){
                            infohtml += '<tr>';
                            infohtml += '<td class="tdclass">'
                            infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                            infohtml += '</td>'
                            infohtml += '<td>'+value['bname']+'</td>'
                            infohtml += '<td>'+value['name']+'</td>'
                            infohtml += '<td>'+unix_to_datetime(value['appointmenttime'])+'</td>'
                            infohtml += '</tr>'
                        });
                        infohtml += '</table>';
                    }

                    $('.record').eq(index-1).html(infohtml);

                }
            },
            ajaxFormatBack: function (data) {
                data.total = data.totalpage;
                data.currentPage = data.currentPage;
            }
        });
    }
    // --------------------借阅申请--------------------------------
    // 同意
    function buttonAgree1(id,bid,uid){
        $.ajax({
            url:'/admin/home/borrowOrReturnApply',
            type:'POST',
            data:{
                id:id,
                bid:bid,
                uid,uid,
                type:1
            },
            success:function(res) {
                if (res == 1) {
                    layer.msg('已同意');
                    window.location.href = '/admin/home/borrowingmanagement';
                }
                else if(res == 2){
                    layer.msg('此人手中有书，不在借给他');
                }
                else {
                    layer.msg('不同意1');
                }
            }
        });
    }
    // 驳回
    function buttonRefuse1(id){
        $.ajax({
            url:'/admin/home/borrowOrReturnApply',
            type:'POST',
            data:{
                id:id,
                type:2
            },
            success:function(res) {
                if (res == 1) {
                    layer.msg('已驳回');
                    window.location.href = '/admin/home/borrowingmanagement';
                }
                else {
                    layer.msg('驳回失败');
                }
            }
        });
    }
    // -------------------归还申请------------------------
    // 同意
    function buttonAgree2(id,bid,uid){
        $.ajax({
            url:'/admin/home/borrowOrReturnApply',
            type:'POST',
            data:{
                id:id,
                bid:bid,
                uid:uid,
                type:3
            },
            success:function(res) {
                if (res == 1) {
                    layer.msg('已同意');
                    window.location.href = '/admin/home/borrowingmanagement';
                }
                else {
                    layer.msg('不同意2');
                }
            }
        });
    }
    // 驳回
   function buttonRefuse2(id){
       $.ajax({
           url:'/admin/home/borrowOrReturnApply',
           type:'POST',
           data:{
               id:id,
               type:4
           },
           success:function(res) {
               if (res == 1) {
                    layer.msg('已驳回');
                    window.location.href = '/admin/home/borrowingmanagement';
               }
               else {
                   layer.msg('驳回失败');
               }
           }
       });
   }
</script>
<script>
    // 搜索
    $('#search').click(function(){
        var name = $('#content').val();
        if(name!=''){
            if(index == 1){
                ajaxSearch(name,index);
            }
            if(index == 2){
                ajaxSearch(name,index);
            }
        }
    })
    function ajaxSearch(name,index){
        $(".pagination").empty();
        $('.pagination').paging({
            total: '',
            currentPage: '',
            showPage: 5,        //显示的页数
            animation: false,
            showJump: false,
            ajaxSubmitType: 'post',
            simpleType: 1,
            url: '/admin/index/search',
            idParameter: "page",
            ajaxData: {name:name,type:2,pageType:index},
            beforeAjaxSubmit: function () {
                PageAPI.AddAjaxData({"pageSize": $(".pageSize").val()});
            },
            ajaxSubmitBack: function (data) {
                console.log(data);
                $('.record').eq(index-1).empty();
                var orderinfo = data.data;
                var type = data.type;
                // alert(type)
                if(orderinfo=='' ||orderinfo==undefined){
                    $(".record").eq(index-1).html(' <h2 style="text-align: center;padding-top:120px;height: 166px;color: red;">暂无数据</h2>');
                    $(".pagination").hide();
                }else{
                    $(".pagination").show();
                    var infohtml="";
                    if(type == 1){
                        infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">';
                        infohtml += '<tr class="firstTr">';
                        infohtml += '<th width="10%">图片</th>';
                        infohtml += '<th width="10%">书名</th>';
                        infohtml += '<th width="10%">申请人</th>';
                        infohtml += '<th width="10%">申请时间</th>';
                        infohtml += '<th width="10%">操作</th>';
                        infohtml += '</tr>';
                        $.each(orderinfo,function(index,value){
                            infohtml += '<tr>';
                            infohtml += '<td class="tdclass">'
                            infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                            infohtml += '</td>'
                            infohtml += '<td>'+value['bname']+'</td>'
                            infohtml += '<td>'+value['name']+'</td>'
                            infohtml += '<td>'+unix_to_datetime(value['applybooktime'])+'</td>'
                            infohtml += '<td>'
                            if(value['expect'] == 1){
                                infohtml += '<input type="button" onclick="" value="同意" id="agree" class="anniu" style="visibility: hidden;"/>';
                                infohtml += '<input type="button" onclick="buttonRefuse1('+value['id']+')" value="驳回" class="anniu"/>';
                            }
                            else{
                                infohtml += '<input type="button" onclick="buttonAgree1('+value['id']+','+value['bid']+','+value['uid']+')" value="同意" id="agree" class="anniu"/>';
                                infohtml += '<input type="button" onclick="buttonRefuse1('+value['id']+')" value="驳回" class="anniu"/>';
                            }

                            infohtml += '</td>'
                            infohtml += '</tr>'
                        });
                        infohtml += '</table>';
                    }
                    // 归还申请
                    else if(type == 2){
                        infohtml += '<table class="providerTable" cellpadding="0" cellspacing="0">';
                        infohtml += '<tr class="firstTr">';
                        infohtml += '<th width="10%">图片</th>';
                        infohtml += '<th width="10%">书名</th>';
                        infohtml += '<th width="10%">借阅人</th>';
                        infohtml += '<th width="10%">借阅时间</th>';
                        infohtml += '<th width="10%">逾期时间</th>';
                        infohtml += '<th width="10%">操作</th>';
                        infohtml += '</tr>';
                        $.each(orderinfo,function(index,value){
                            infohtml += '<tr>';
                            infohtml += '<td class="tdclass">'
                            infohtml += '<img src="'+value['img']+'" class="imgclass"/>'
                            infohtml += '</td>'
                            infohtml += '<td>'+value['bname']+'</td>'
                            infohtml += '<td>'+value['name']+'</td>'
                            if(value['returntime'] == ''){
                                infohtml += '<td>' + unix_to_datetime(value['booktime']) + '-至今</td>'
                            }
                            else {
                                infohtml += '<td>' + unix_to_datetime(value['booktime']) + '-' + unix_to_datetime(value['returntime']) + '</td>'
                            }

                            if(value['isBeOverdue'] == ''){
                                infohtml += '<td>未逾期</td>';
                            }
                            else{
                                infohtml += '<td>'+value['isBeOverdue']+'天</td>';
                            }
                            infohtml += '<td>'
                            infohtml += '<input type="button" onclick="buttonAgree2('+value['id']+','+value['bid']+','+value['uid']+')" value="同意" class="anniu"/>';
                            infohtml += '<input type="button" onclick="buttonRefuse2('+value['id']+')" value="驳回" class="anniu"/>';
                            infohtml += '</td>';
                            infohtml += '</tr>'
                        });
                        infohtml += '</table>';
                    }
                    $('.record').eq(index-1).html(infohtml);
                    // $('.record').eq(index-1).html(infohtml);

                }
            },
            ajaxFormatBack: function (data) {
                data.total = data.totalpage;
                data.currentPage = data.currentPage;
            }
        });
    }
</script>
</body>
</html>